package com.haidechizi.leetcode;

/**
 * @author: wangdejun
 * @create: 2020-04-03 10:45
 **/
public class _18_删除链表的节点 {

    public ListNode deleteNode(ListNode head, int val) {
        if(head.val == val) {
            return head.next;
        }
        ListNode current = head;
        while (current.next != null) {
            ListNode next = current.next;
            if(next.val == val) {
                if(next.next != null) {
                    current.next = next.next;
                } else {
                    current.next = null;
                }
                return head;
            }
            current = current.next;
        }
        return head;
    }
}
